// pages/index/psyQA/psyQATitle/psyQATitle.js
let app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url: '',
    id: '',
    psych: '',
    psychreply: '',
    showReply: false,
    inputValue: "",
    userId: '',
    systemInfo: '',
    userName: ''
  },
  getPsych() {
    wx.showLoading({
      title: "正在加载中..."
    })
    wx.request({
      url: this.data.url + 'psych/' + this.data.id,
      method: "GET",
      success: (resp) => {
        this.setData({
          psych: resp.data.data,
        })
        console.log(this.data.userName + '----------')
        console.log(this.data.id+"77777777777777")
      },
      complete: () => {
        setTimeout(() => {
          wx.hideLoading()
        }, 100);
        wx.stopPullDownRefresh()
        this.setData({
          isLoading: false
        })
      }
    })
  },
  getPsychReply() {
    wx.showLoading({
      title: "正在加载中..."
    })
    wx.request({
      url: this.data.url + 'psychreply/' + this.data.id,
      method: "GET",
      success: (resp) => {
        this.setData({
          psychreply: resp.data.data,
          userId: resp.data.data.userId
        })
        console.log(resp.data)
      },
      complete: () => {
        setTimeout(() => {
          wx.hideLoading()
        }, 100);
        wx.stopPullDownRefresh()
        this.setData({
          isLoading: false,
        })
      }
    })
  },

  showFullReply() {
    this.setData({
      showReply: true
    });
  },
  hideFullReply() {
    this.setData({
      showReply: false,
      inputValue: ""
    });
  },
  handleInput(e) {
    this.setData({
      inputValue: e.detail.value
    });
  },
  handleSend() {
    if (!this.data.inputValue.trim()) {
      wx.showToast({
        title: "内容不能为空",
        icon: "none"
      });
      return;
    }
    wx.showToast({
      title: "评论成功！",
      icon: "success"
    });
    wx.request({
      url: this.data.url + 'psychreply',
      method: "POST",
      data: {
        replyContent: this.data.inputValue,
        userId: this.data.id,
        qaId: this.data.id
      },
    })
    this.getPsychReply()
    this.hideFullReply();
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      url: app.globalData.url,
      id: options.id,
      userName: options.userName
    })
    console.log(this.data.id)
    this.getPsych()
    this.getPsychReply()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getPsych();
    this.getPsychReply()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})